import React, { Component } from 'react';
import { connect } from 'dva';
import { message, Modal, Pagination, Popconfirm, Button } from 'antd';
import styles from './../Users.css';
import moment from 'moment';
import Factory from '../../factory';
import numeral from 'numeral';
import * as datetime from '../../../utils/datetime'
import dataEditCreate from '../../addons/DataEdit'
import dataTableCreate from '../../addons/DataTable'
import * as menuService from '../../../services/menus'
import * as com from '../../../utils/common';

const daoName = "INDI_SAVE_ACCO";
const ButtonGroup = Button.Group;
const renderNumber = (num) => {
  let value = ''
  if (num) {
    value = numeral(num).format('0,0')
  }
  return value
};
const columns = [
    { title: '帐号', dataIndex: 'Zhanghao', key: 'Zhanghao', width: 150, sorter: true, dispaly: true, filter: true },
    { title: '卡号', width: 150, sorter: true, dataIndex: 'Khao', key: 'Khao', dispaly: true, filter: true },
    { title: '科目', dataIndex: 'Km', key: 'Km', width: 180, sorter: true, dispaly: true, filter: true },
    { title: '客户名称', dataIndex: 'Khmc', key: 'Khmc', width: 140, sorter: true, dispaly: true, filter: true },
    { title: '身份证号', dataIndex: 'Sfzh', key: 'Sfzh', width: 180, sorter: true, dispaly: true, filter: true },
    { title: '开户网点', width: 140, sorter: true, dataIndex: 'Khwd', key: 'Khwd', dispaly: true, filter: true },
    { title: '币种', dataIndex: 'Bizhong', key: 'Bizhong', width: 140, sorter: true, dispaly: true, filter: true },
    { title: '执行利率', dataIndex: 'Ccly', key: 'Ccly', width: 140, sorter: true, dispaly: true, filter: true },
    { title: '当前余额', className: 'column-money', render: data => com.formatNumber(data.Dqye), caption: "Dqye", key: 'Dqye', width: 140, sorter: true, dispaly: true, filter: true },
    { title: '开户日', width: 100, sorter: true, key: 'Khr', caption: "Khr", render: data => datetime.format(data.Khr, "yyyy-MM-dd"), dispaly: true, filter: true },
    { title: '起息日', width: 100, sorter: true, key: 'Qxr', caption: "Qxr", render: data => datetime.format(data.Qxr, "yyyy-MM-dd"), dispaly: true, filter: true },
    { title: '到期日', width: 100, sorter: true, key: 'Dqr', caption: "Dqr", render: data => datetime.format(data.Dqr, "yyyy-MM-dd"), dispaly: true, filter: true },
    { title: '客户经理1', width: 180, sorter: false, dataIndex: 'YG1', key: 'YG1', dispaly: true, filter: false },
    { title: '分配比例1(%)', width: 100, sorter: false, className: "column-money", caption:'ZB1',render: data => renderNumber(data.ZB1), key: 'ZB1', dispaly: true, filter: false },
    { title: '客户经理2', width: 180, sorter: false, dataIndex: 'YG2', key: 'YG2', dispaly: true, filter: false },
    { title: '分配比例2(%)', width: 100, sorter: false, className: "column-money", caption:'ZB2',render: data => renderNumber(data.ZB2), key: 'ZB2', dispaly: true, filter: false },
    { title: '客户经理3', width: 180, sorter: false, dataIndex: 'YG3', key: 'YG3', dispaly: true, filter: false },
    { title: '分配比例3(%)', width: 100, sorter: false, className: "column-money", caption:'ZB3',render: data => renderNumber(data.ZB3), key: 'ZB3', dispaly: true, filter: false },
    { title: '客户经理4', width: 180, sorter: false, dataIndex: 'YG4', key: 'YG4', dispaly: true, filter: false },
    { title: '分配比例4(%)', width: 100, sorter: false, className: "column-money", caption:'ZB4',render: data => renderNumber(data.ZB4), key: 'ZB4', dispaly: true, filter: false },
    { title: '客户经理5', width: 180, sorter: false, dataIndex: 'YG5', key: 'YG5', dispaly: true, filter: false },
    { title: '分配比例5(%)', width: 100, sorter: false, className: "column-money", caption:'ZB5',render: data => renderNumber(data.ZB5), key: 'ZB5', dispaly: true, filter: false },
  ];
const controls = [
    { name: 'Sfzh', required: true, type: 'text', label: '身份证号', grid: 12 / 24 },
    { name: 'Km', required: true, type: 'text', label: '科目', grid: 12 / 24 },
    { name: 'Zhanghao', required: true, type: 'text', label: '帐号', grid: 12 / 24 },
    { name: "Khao", label: "卡号", type: "tel", grid: 12 / 24 },
    { name: "Khwd", label: "开户网点", type: "text", grid: 12 / 24 },
    { name: 'Bizhong', required: true, type: 'text', label: '币种', grid: 12 / 24 },
    { name: 'Khmc', required: true, type: 'text', label: '客户名称', grid: 12 / 24 },
    { name: 'Ccly', required: true, type: 'text', label: '执行利率', grid: 12 / 24 },
    { name: 'Dqye', required: true, type: 'alphanum', label: '当前余额', grid: 12 / 24 },
    { name: "Khr", label: "开户日", type: "date", grid: 12 / 24, dataType: "date" },
    { name: "Qxr", label: "起息日", type: "date", grid: 12 / 24, dataType: "date" },
    { name: "Dqr", label: "到期日", type: "date", grid: 12 / 24, dataType: "date" },

]
const DataTable = dataTableCreate(daoName);
class INDI_SAVE_ACCOS extends Component {
    constructor(props) {
        super(props);
        this.state = {
            dataChange: false
        };
    }
    componentDidMount() {
        this.props.dispatch({
            type: `${daoName}/setKeyName`,
            payload: { keyName: "ID", permID: this.props.permID }
        });
        let sort = {
            field: 'Khr',
            order: 'descend'
          }
        this.props.dispatch({
            type: `${daoName}/fetch`,
            payload: { daoName, page: 1, pageSize: 20 ,sorter: sort}
        });
        this.loadOptionData();
    }
    loadOptionData() {
        let options = []
        controls.map(c => {
            if (c.fetch) {
                let f = c.fetch;
                if (c.type === 'cascader-select') {
                    f.isCascader = true;
                }
                if (c.type !== 'search') {
                    options.push(f);
                }
            }
        })
        if (daoName && options.length > 0) {
            this.props.dispatch({ type: `${daoName}/fetchOptions`, payload: { options } });
        }
    }
    render() {
        let { showEdit, record,permID } = this.props
        return (
            <div className={styles.normal} style={{ background: '#fff', marginTop: -16, padding: '5px 5px' }}>
                <div>
                    <div className={styles.create}>
                    </div>
                    <DataTable ref="userTable" daoName={daoName} columns={columns} controls={controls} permID={permID}/>
                </div>
            </div>
        )
    }
}
function mapStateToProps(state) {
    const { showEdit, record, selectedRowKeys, keyName } = state[daoName];
    return {
        showEdit,
        selectedRowKeys,
        keyName,
        record
    }
}
INDI_SAVE_ACCOS = connect(mapStateToProps)(INDI_SAVE_ACCOS)
export default INDI_SAVE_ACCOS;
let render = (props) => React.createElement(INDI_SAVE_ACCOS, props);

let f = new Factory()
f.set("INDI_SAVE_ACCOS", render)
